package edu.sjtu.grid.workflow.group;

import edu.sjtu.grid.workflow.Util;
import edu.sjtu.grid.workflow.facts.Job;
import edu.sjtu.grid.workflow.facts.PC;

public class MDPKey {

	private Job job = null;
	private double deadline = 0;
	private PC pc = null;
	//private double unit = 0;
	
	public MDPKey(Job job, double deadline, PC pc, double unit)
	{
		this.job = job;
		this.deadline = deadline;
		this.pc = pc;
		//this.unit = unit;
	}
	
	public String toString()
	{
		String s = "";
		s += "[" + job.getId() + "," + pc.getId() + "," + deadline + "]";
		return s;
	}

	public Job getJob() {
		return job;
	}

	public double getDeadline() {
		return deadline;
	}

	public PC getPc() {
		return pc;
	}

	public boolean equals(Object obj2) {
		if(obj2 instanceof MDPKey == false)
			return false;
		MDPKey obj = (MDPKey)obj2;
		if(job == obj.getJob()
			&& pc == obj.getPc()
			&& Util.isEqual(deadline, obj.getDeadline()))
			//&& Math.abs(deadline - obj.getDeadline()) < 0.0001) //ok
			//&& Math.abs(deadline - obj.getDeadline()) < this.unit / 10) //ok
			return true;
		else
			return false;
	}
	
	public int hashCode() {
		return job.hashCode() + pc.hashCode() + (int)deadline;
	}
}
